class UsersController < ApplicationController

	before_filter :check_session,			# filter routine (applied before the action starts) checks for session
		:only => [:logout, :set_as_default] 	# actions where filter is applied


	# POST /login
	def login
		user = User.authenticate(params[:username],params[:password])
		if user
			session[:current_user_id] = user.id
			flash[:notice] = "logged in"
			redirect_to '/home'
		else
			flash[:notice] = "Wrong username/password"
			redirect_to root_url
		end
	end

	# POST /logout
	def logout
		session[:current_user_id] = nil
		flash[:notice] = "Logged out"
		redirect_to root_url
	end

	# POST /set_default_resume
	def set_default_resume
		@user = User.find(session[:current_user_id])	
		@user.default_resume = params["resume_id"]
		result = @user.save
		if (params["ajax"]=="true")
			if result
					render :json => { :retVal => "set" }		
			else
					render :json => { :retVal => "error"}
			end
		else
			redirect_to root_url
		end	
	end
	
end

